
package vip.xiaonuo.biz.modular.lancerUsercoupon.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import vip.xiaonuo.common.annotation.CommonLog;
import vip.xiaonuo.common.pojo.CommonResult;
import vip.xiaonuo.common.pojo.CommonValidList;
import vip.xiaonuo.biz.modular.lancerUsercoupon.entity.BizUserCoupon;
import vip.xiaonuo.biz.modular.lancerUsercoupon.param.BizUserCouponAddParam;
import vip.xiaonuo.biz.modular.lancerUsercoupon.param.BizUserCouponEditParam;
import vip.xiaonuo.biz.modular.lancerUsercoupon.param.BizUserCouponIdParam;
import vip.xiaonuo.biz.modular.lancerUsercoupon.param.BizUserCouponPageParam;
import vip.xiaonuo.biz.modular.lancerUsercoupon.service.BizUserCouponService;

import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;

/**
 * 优惠券控制器
 *
 * @author Lancer
 * @date  2024/03/15 11:48
 */
@Api(tags = "优惠券控制器")
@ApiSupport(author = "LANCER_TEAM", order = 1)
@RestController
@Validated
public class BizUserCouponController {

    @Resource
    private BizUserCouponService bizUserCouponService;

    /**
     * 获取优惠券分页
     *
     * @author Lancer
     * @date  2024/03/15 11:48
     */
    @ApiOperationSupport(order = 1)
    @ApiOperation("获取优惠券分页")
    @SaCheckPermission("/biz/userCoupon/page")
    @GetMapping("/biz/userCoupon/page")
    public CommonResult<Page<BizUserCoupon>> page(BizUserCouponPageParam bizUserCouponPageParam) {
        return CommonResult.data(bizUserCouponService.page(bizUserCouponPageParam));
    }

    /**
     * 添加优惠券
     *
     * @author Lancer
     * @date  2024/03/15 11:48
     */
    @ApiOperationSupport(order = 2)
    @ApiOperation("添加优惠券")
    @CommonLog("添加优惠券")
    @SaCheckPermission("/biz/userCoupon/add")
    @PostMapping("/biz/userCoupon/add")
    public CommonResult<String> add(@RequestBody @Valid BizUserCouponAddParam bizUserCouponAddParam) {
        bizUserCouponService.add(bizUserCouponAddParam);
        return CommonResult.ok();
    }

    /**
     * 编辑优惠券
     *
     * @author Lancer
     * @date  2024/03/15 11:48
     */
    @ApiOperationSupport(order = 3)
    @ApiOperation("编辑优惠券")
    @CommonLog("编辑优惠券")
    @SaCheckPermission("/biz/userCoupon/edit")
    @PostMapping("/biz/userCoupon/edit")
    public CommonResult<String> edit(@RequestBody @Valid BizUserCouponEditParam bizUserCouponEditParam) {
        bizUserCouponService.edit(bizUserCouponEditParam);
        return CommonResult.ok();
    }

    /**
     * 删除优惠券
     *
     * @author Lancer
     * @date  2024/03/15 11:48
     */
    @ApiOperationSupport(order = 4)
    @ApiOperation("删除优惠券")
    @CommonLog("删除优惠券")
    @SaCheckPermission("/biz/userCoupon/delete")
    @PostMapping("/biz/userCoupon/delete")
    public CommonResult<String> delete(@RequestBody @Valid @NotEmpty(message = "集合不能为空")
                                                   CommonValidList<BizUserCouponIdParam> bizUserCouponIdParamList) {
        bizUserCouponService.delete(bizUserCouponIdParamList);
        return CommonResult.ok();
    }

    /**
     * 获取优惠券详情
     *
     * @author Lancer
     * @date  2024/03/15 11:48
     */
    @ApiOperationSupport(order = 5)
    @ApiOperation("获取优惠券详情")
    @SaCheckPermission("/biz/userCoupon/detail")
    @GetMapping("/biz/userCoupon/detail")
    public CommonResult<BizUserCoupon> detail(@Valid BizUserCouponIdParam bizUserCouponIdParam) {
        return CommonResult.data(bizUserCouponService.detail(bizUserCouponIdParam));
    }
}
